package com.jomoo.scs.utils;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.TimeZone;

public class PublicUtils {

	/**
	 * 获取完整异常信息
	 * 
	 * @param e
	 * @return
	 */
	public static String getExceptionDetail(Exception e) {
		StringBuffer stringBuffer = new StringBuffer(e.toString() + "\n");
		StackTraceElement[] messages = e.getStackTrace();
		int length = messages.length;
		for (int i = 0; i < length; i++) {
			stringBuffer.append("\t" + messages[i].toString() + "\n");
		}
		return stringBuffer.toString();
	}

	/**
	 * 将数据保留两位小数
	 */
	public static double getTwoDecimal(double num){
		DecimalFormat dFormat = new DecimalFormat("#.00");
		String yearString = dFormat.format(num);
		Double temp = Double.valueOf(yearString);
		return temp;
	}
	
	
	
	
	public static String convertDataTime(Object datatime) throws ParseException{
		if(datatime == null) return "";
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+ssss");
		df.setTimeZone(TimeZone.getTimeZone("UTC"));
		
		return  format.format(df.parse(datatime.toString()));
	}
	
	public static String getDateString(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return  format.format(new Date());
	}
	
	public static String getDay(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		return  format.format(new Date());
	}
	
	
	/**
	 * 获取当前日期 结尾： 00:00:00
	 * 
	 * @return
	 */
	public static String getCurrentTime() {
		Date date = new Date();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		// System.out.println(format.format(date).toString().concat("
		// 00:00:00"));
		return format.format(date).toString().concat(" 00:00:00");
	}

	public static String getBeginTime(String date) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date dt = sdf.parse(date);
		Calendar rightNow = Calendar.getInstance();
		rightNow.setTime(dt);
		rightNow.add(Calendar.DAY_OF_MONTH, -1);
		Date dt1 = rightNow.getTime();
		return sdf.format(dt1).concat(" 00:00:00");

	}

	
	

	public static void main(String [] args){
		
		HashMap map = new HashMap();
		map.put("10", true);
		map.put("20", true);
		map.put("30", false);
		map.put("40", true);
		for(Object obj : map.values()){
//			System.out.println();
			if(Boolean.valueOf(obj.toString())){
				System.out.println("1");

			}else{
				System.out.println("2");

			}
		}
	 
	}
}
